package org.zephyr.fastboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zephyr.fastboot.entity.SysUser;
import org.zephyr.fastboot.service.SysUserService;

import java.util.List;

/**
 * @Author: ZephyrGao
 * @Date: 2024/7/15 09:43
 * @Description:
 */

@RestController
@RequestMapping("/users")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @GetMapping
    public List<SysUser> getAllUsers() {
        return sysUserService.getAllUsers();
    }

    public SysUser getUserByName(@PathVariable String name) {
        return sysUserService.getUserByName(name);
    }

    @GetMapping("/{id}")
    public SysUser getUserById(@PathVariable Long id) {
        return sysUserService.getUserById(id);
    }

    @PostMapping
    public void saveUser(@RequestBody SysUser user) {
        sysUserService.saveUser(user);
    }

    @PutMapping
    public void updateUser(@RequestBody SysUser user) {
        sysUserService.updateUser(user);
    }

    @DeleteMapping("/{id}")
    public void deleteUser(@PathVariable Long id) {
        sysUserService.deleteUser(id);
    }
}
